#pragma once
#include "Protocol.hpp"

class Cal
{
public:
    Response Execute(Request& req)
    {
        std::cout<<"开始处理......"<<std::endl;
        Response res(0,0);
        switch (req.GetOper())
        {
        case '+':
            res.SetResult(req.GetX() + req.GetY());
            break;
        case '-':
            res.SetResult(req.GetX() - req.GetY());
            break;
        case '*':
            res.SetResult(req.GetX() * req.GetY());
            break;
        case '/':
            if(req.GetY() == 0)
            {
                res.SetCode(1);//除零异常
            }
            else
            {
                res.SetResult(req.GetX() / req.GetY());
            }
            break;
        case '%':
            if(req.GetY() == 0)
            {
                res.SetCode(2);//模零异常
            }
            else
            {
                res.SetResult(req.GetX() % req.GetY());
            }
            break;
        default:
            res.SetCode(3);//非法操作
            break;
        }
        return res;
    }
};